//
//  SmallDecisionsHqView.m
//  SmallDecisions
//
//  Created by 李付雄 on 2025/7/26.
//

#import "SmallDecisionsHqView.h"
@interface SmallDecisionsHqView()

@property (nonatomic, strong)UIImageView *hqImageView;
@property (nonatomic, assign)BOOL isStart;
@property (nonatomic, strong)NSArray *images;

@end

@implementation SmallDecisionsHqView

- (instancetype)init {
    self = [super init];
    if(self != nil) {
        [self setSmallDecisionsHqViewSubviews];
    }
    return self;
}

- (NSArray *)images {
    if(!_images) {
        _images = [NSArray arrayWithObjects:@"cloth_img",@"stone_img",@"scissors_img", nil];
    }
    return _images;
}

- (void)setSmallDecisionsHqViewSubviews {
    UIImageView *hqImageView = [[UIImageView alloc] init];
    hqImageView.animationImages = @[[UIImage imageNamed:@"stone_img"], [UIImage imageNamed:@"scissors_img"], [UIImage imageNamed:@"cloth_img"]];
    [self addSubview:hqImageView];
    [hqImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        make.width.height.mas_equalTo(150);
    }];
    hqImageView.animationDuration = 1.0;
    [hqImageView startAnimating];
    self.hqImageView = hqImageView;
}

- (void)startAnimating {
    [self.hqImageView startAnimating];
}

- (void)stopAnimating {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.hqImageView stopAnimating];
        self.hqImageView.image = [UIImage imageNamed:self.images[arc4random() % 3]];
    });
}

@end
